//
//  ConfirmAddressView.m
//  easyTaxi
//
//  Created by ellenpage on 13-1-4.
//  Copyright (c) 2013年 ellenpage. All rights reserved.
//

#import "Constant.h"
#import "ConfirmAddressView.h"
#import "PassValueClass.h"

@interface ConfirmAddressView ()<UITableViewDataSource,UITableViewDelegate>

@property (retain, nonatomic) NSMutableArray *dataArray;   //地址数组

- (IBAction)removeThisView;

@end

@implementation ConfirmAddressView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self = [[[NSBundle mainBundle] loadNibNamed:@"ConfirmAddressView" owner:self options:nil] objectAtIndex:0];
        
        [self initialData];

    }
    return self;
}

- (void)initialData
{
    _addressResultTBView.delegate   = self;
    _addressResultTBView.dataSource = self;
    
    _dataArray = [NSMutableArray array];
}

#pragma mark - TableViewDataSource Delegate - TableView Datasource代理

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
	return [_resultpoi.poiInfoList count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	static NSString *tableIdentifier = @"SimpleTableIdentifier";
	UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:tableIdentifier];
    cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableIdentifier];
    UILabel *titleLbl   = [[UILabel alloc] initWithFrame:CGRectMake(0, 6, 300, 21)];
    UILabel *contentLbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, 300, 21)];

    titleLbl.text   = [[_resultpoi.poiInfoList objectAtIndex:indexPath.row] name];
    titleLbl.backgroundColor = [UIColor clearColor];
    titleLbl.textAlignment = UITextAlignmentCenter;
    titleLbl.font = [UIFont systemFontOfSize:17];

    contentLbl.text = [[_resultpoi.poiInfoList objectAtIndex:indexPath.row] address];
    contentLbl.backgroundColor = [UIColor clearColor];
    contentLbl.textAlignment = UITextAlignmentCenter;
    contentLbl.font = [UIFont systemFontOfSize:14];
        
    [cell.contentView addSubview:titleLbl];
    [cell.contentView addSubview:contentLbl];
    
	return cell;
}

#pragma mark - TableView Delegate - TableView 代理

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath//选择一个地址
{
    [PassValueClass sharedIntance].poi = nil;
    [PassValueClass sharedIntance].poi = [_resultpoi.poiInfoList objectAtIndex:indexPath.row];
    
    self.hidden = YES;

    bool isFromAddressLiatView = [[NSUserDefaults standardUserDefaults] boolForKey:kIsFromAddressListView];
    if (isFromAddressLiatView)
    {
        [[NSNotificationCenter defaultCenter] postNotificationName:kGetEndAddressNoti_Addresslist object:nil];
    }
    else
    {
        if ([self.delegate respondsToSelector:@selector(removeRequestView)])
        {
            [self.delegate removeRequestView];
        }

        if ( [self.delegate respondsToSelector:@selector(getAddress)])
        {
            [self.delegate getAddress];
        }
    }
}


- (IBAction)removeThisView
{
    self.hidden = YES;
}
@end
